package com.atguigu.async;

import com.atguigu.exception.SleepUtils;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class FutureDemo4 {
    public static void main(String[] args) throws Exception{
        runAsync1();
        System.out.println("main");
        SleepUtils.sleep(3);
    }

    public static void runAsync1(){
        CompletableFuture<String> supplyAsync = CompletableFuture.supplyAsync(new Supplier<String>() {
            @Override
            public String get() {
                System.out.println(Thread.currentThread().getName()+"你好supplyAsync");
                SleepUtils.sleep(1);
                return "java0317";
            }
        });
        supplyAsync.thenAccept(new Consumer<String>() {
            @Override
            public void accept(String acceptValue) {
                System.out.println(Thread.currentThread().getName()+"第一个接收supply返回值"+acceptValue);
            }
        });
        supplyAsync.thenAccept(new Consumer<String>() {
            @Override
            public void accept(String acceptValue) {
                System.out.println(Thread.currentThread().getName()+"第二个接收supply返回值"+acceptValue);
            }
        });
    }

}
